﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim V_XM As String
	Dim V_CH As String
	Dim V_BHID As Int
	
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim lsvBHZD As ListView
	Dim HttpJobTool As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHZDInfo")
	Activity.Title = "病人诊断信息-"  & V_CH & " " &V_XM 
	
	InitLayOut

	'RefreshData
	
End Sub

Sub Activity_Resume
	RefreshData
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut

End Sub

Sub RefreshData
	Dim sURL,sSession,sText,sBHID As String
	
	lsvBHZD.Clear
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sBHID = PublicVar.GV_DesTool.Base64encrypt(V_BHID)
	
	sText = "Session=" & sSession & "&BHID=" & sBHID

	sURL = PublicVar.GetServerUrl&"/getbhzdinfo"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	
	ProgressDialogShow("正在获取数据，请稍候...")	

End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub


Sub HttpJobSuccess(Job As HttpJob)  
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	Dim lsRecords As List
	
	ProgressDialogHide
	
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	lsRecords = PublicVar.GV_JSonTool.NextArray
	
	SetBHZDInfo(lsRecords)

End Sub

Sub HttpJobError(Job As HttpJob)   
	Dim sMsg As String
	ProgressDialogHide
		
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取病人基本信息失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)

End Sub

Sub SetBHZDInfo(lsRecords As List)
	Dim sLine1,sLine2,sZDLX,sZDZL As String
	Dim mapResult As Map
	Dim iFlag As Int
	Dim lblItem As Label
	
	lsvBHZD.Clear
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		sZDLX = ""
		sZDZL = ""
		iFlag = mapResult.Get("ZDLX")
		Select iFlag 
		Case 0	
			sZDLX = "主"
		Case 16
			sZDLX = "次"
		Case 48 
			sZDLX = "并"
		End Select
		
		iFlag = mapResult.Get("ZDZL")
		
		Select iFlag
			Case 0 
				sZDZL = "门诊诊断"
			Case 1 
				sZDZL = "住院诊断"
			Case  2 
				sZDZL = "术前诊断"
			Case  3 
				sZDZL = "术后诊断"
			Case 4 
				sZDZL = "入院诊断"			
			Case  5 
				sZDZL = "出院诊断"				
		End Select		
		
		sLine1 = mapResult.Get("ZDRQ") & " "& mapResult.Get("LCZD") 		
		sLine2 = sZDLX & " " & sZDZL & " " & mapResult.Get("ZDYSMC")
		lsvBHZD.AddTwoLines(sLine1,sLine2)
'		If sZDLX ="主" Then
'			lblItem = lsvBHZD.TwoLinesLayout.Label
'			lblItem.TextColor = Colors.Red
'		End If
	Next

End Sub



